<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-qdb-add">

        <input id="treeId" name="pid" type="hidden" th:value="${qdb.id}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label ">上级：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" id="treeName" onclick="selectTree()" readonly="true"
                       th:value="${qdb.name}"/>
            </div>
        </div>
            <div class="form-group">
            <label class="col-sm-3 control-label">知识点编号：</label>
            <div class="col-sm-8">
                <input id="id" name="id" class="form-control"
                       type="text">
            </div>
        </div>
    
            <div class="form-group">
            <label class="col-sm-3 control-label">题库名称：</label>
            <div class="col-sm-8">
                <input id="name" name="name" class="form-control"
                       type="text">
            </div>
        </div>
    
            <!-- <div class="form-group">
            <label class="col-sm-3 control-label">题库图标：</label>
            <div class="col-sm-8">
                <input id="logo" name="logo" class="form-control"
                       type="text">
            </div>
        </div> -->
    
            <div class="form-group">
			<label class="col-sm-3 control-label">是否开放（默认on开放）：</label>
			<div class="col-sm-8">
				<div class="onoffswitch">
					<input type="checkbox" checked="true" class="onoffswitch-checkbox" id="status" name="status">
					<label class="onoffswitch-label" for="status">
						<span class="onoffswitch-switch"></span>
						<span class="onoffswitch-inner"></span>
					</label>
				</div>
			</div>
		</div>
    
            <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <input id="remark" name="remark" class="form-control"
                       type="text">
            </div>
        </div>
    
   
    </form>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
    var prefix = ctx + "exam/qdb"
    $("#form-qdb-add").validate({
		onkeyup: false,
		rules:{
			name:{
				required:true,
				remote: {
	                url: prefix + "/checkQdbNameUnique",
	                type: "post",
	                dataType: "json",
	                data: {
	                	"parentId": function() {
	                		return $("input[name='pid']").val();
	                    },
	                	"name" : function() {
	                        return $.common.trim($("#name").val());
	                    },
	                    "id" : function() {
	                        return $.common.trim($("#id").val());
	                    }
	                },
	                dataFilter: function(data, type) {
	                	return data;
	                }
	            }
			},
			id:{
				required:true,
				digits:true
			}
		},
		messages: {
	        "name": {
	            remote: "题库目录已经存在"
	        }
	    }
	});

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/addDo", $('#form-qdb-add').serialize());
        }
    }

    function selectTree() {
        var treeId = $("#treeId").val();
    	var id = $.common.isEmpty(treeId) ? "1" : $("#treeId").val();
        var options = {
            title: '选择上级',
            width: "380",
            url: prefix + "/selectTree/" + id,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        //var tree = layero.find("iframe")[0].contentWindow.$._tree;
        // 不允许最后层级节点选择
        // if ($.tree.notAllowLastLevel(tree)) {
            var body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        // }
    }
</script>
</body>
</html>
